package client.comm.baoding.adapter

import android.content.Context
import android.content.Intent
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import client.comm.commlib.base.BaseLoadmoreAdapter
import client.comm.commlib.base.BindingViewHoder
import client.comm.baoding.R
import client.comm.baoding.api.bean.LevelIncome
import client.comm.baoding.api.bean.RankingList
import client.comm.baoding.api.bean.TdBean
import client.comm.baoding.api.bean.UserInfo
import client.comm.baoding.databinding.*
import client.comm.baoding.ui.TdSubActivity
import client.comm.baoding.ui.TdlstjActivity
import client.comm.baoding.ui.TuiGuangActivity
import client.comm.commlib.utils.StoreUtil

import com.bumptech.glide.RequestManager

class RankingAdapter : BaseLoadmoreAdapter<RankingList.Ranking> {

    val manager: RequestManager

    constructor(context: Context, manager: RequestManager) : super(context) {
        this.manager = manager
    }

    override fun createVh(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return BindingViewHoder(
            DataBindingUtil.inflate(
                layoutInflater,
                R.layout.item_rank,
                parent,
                false
            )
        )
    }

//    fun submitData(list: MutableList<String?>) {
//        super.submitList(list)
//    }

    override fun bindVh(holder: RecyclerView.ViewHolder, position: Int) {
        val bindingViewHolder = holder as BindingViewHoder<ViewDataBinding>
        val binding = bindingViewHolder.binding as ItemRankBinding
        binding.event = this
        var bean = getItem(position)
        binding.bean = bean

        binding.pos = "${position}"
        if (bean.avatar != null) {
            manager.load(bean.avatar).error(R.mipmap.ic_launcher_round)
                .into(binding.img)
        } else {
            binding.img.setImageResource(R.mipmap.ic_launcher_round)
        }
    }

    /* fun onItemClick(b: TdBean.Sub) {
         context.startActivity(Intent(context, TdSubActivity::class.java).apply {
             putExtra("bean", b.id)
         })
     }*/


    fun tuiguang() {
        context.startActivity(Intent(context, TuiGuangActivity::class.java))
    }

    /**
     * 历史推荐
     */
    open fun lstj() {
//        startActivity(Intent(context, TdActivity::class.java).apply {
//            putExtra("bean", StoreUtil.getBean<UserInfo>(requireContext())!!.id)
//        })

//        context.startActivity(Intent(context, TdlstjActivity::class.java)
//            .apply {
//                putExtra("bean", StoreUtil.getBean<UserInfo>(context)!!.id)
//            }
//        )
    }

}